// pages/passoword/passoword.js
const app = getApp(), core = require('../../utils/core'), WeValidator = require('../../utils/we-validator');
Page({

  /**
   * 页面的初始数据
   */
  data: {

  },

  /**
   * 生命周期函数--监听页面加载
   */
  onLoad: function (options) {

  },

  /**
   * 生命周期函数--监听页面卸载
   */
  onUnload: function () {

  },

  submit(event) {
    let data = event.detail.value;
    let validator = new WeValidator({
      rules: {
        password: {required:true,minlength:3},
        password2: {required:true,equalTo:'password'}
      },
      messages: {
        password: {required:'请输入新密码',minlength:'请输入3-20位密码'},
        password2: {required:'请再次输入密码',equalTo:'两次密码输入不一致'}
      }
    });
    if(!validator.checkData(data)) {
      return;
    }
    core.post({url:'user/password',data:data,success:ret=>{
      wx.navigateBack();
      wx.showToast({title: '修改成功',icon:'none'});
    }});
  }

});
